package com.zzyl.service.customer.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.Reservation;
import com.zzyl.mapper.CustomerReservationMapper;
import com.zzyl.service.customer.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description CustomerReservationServiceImpl
 * @Author chenchuang
 * @Date 2024-08-29
 */
@Service
public class CustomerReservationServiceImpl implements CustomerReservationService {

    @Autowired
    private CustomerReservationMapper customerReservationMapper;

    @Override
    public Long cancelledCount() {
        Long id = UserThreadLocal.getUserId();
        Long count = customerReservationMapper.getCancelled(id);
        return count;
    }

    @Override
    public void add(ReservationVo reservationVo) {
        Reservation reservation = new Reservation();
        BeanUtils.copyProperties(reservationVo, reservation);
        reservation.setStatus(0);
        customerReservationMapper.insert(reservation);
    }

    @Override
    public PageResponse<ReservationVo> getByPage(Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<ReservationVo> page = customerReservationMapper.selectByPage(status);
        PageResponse<ReservationVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    @Override
    public void cancel(Long id) {
        customerReservationMapper.updateStatus(id);
    }

    @Override
    public List<TimeCountVo> countEachTime(LocalDateTime time,LocalDateTime endTime) {

        List<TimeCountVo> timeCountVoList=customerReservationMapper.countEachTime(time,endTime);

        return timeCountVoList;
    }
}
